package com.yylending.las.lending.increase;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yylending.las.Global;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by Pengrf on 2017/11/20.
 * Copyright  2017 www.yyfax.com. All Rights Reserved.
 */
public class CheckPromoteStatusModel extends Model {
	public static final int CHECK_PROMOTE_STATUS = 999111;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		switch (functionalCode) {
			case CHECK_PROMOTE_STATUS:
				return service.getPromoteStatus(Global.LOGIN_TOKEN, (EmptyEntity) params);

		}
		return null;
	}

	@Override
	public void onNext(Object entity) {
		BaseResultEntity result = cast(entity);
		switch (result.requestCode) {
			case CHECK_PROMOTE_STATUS:
				CheckPromoteStatusResult checkPromoteStatus = cast(entity);
				EventAgent.post(checkPromoteStatus);
				break;
		}

	}

	private interface Service {
		@POST("server/loan/checkPromoteStatus")
		Observable<CheckPromoteStatusResult> getPromoteStatus(@Header("token") String token, @Body EmptyEntity params);

	}

	static class CheckPromoteStatusResult extends BaseResultEntity<PromoteStatus> {
	}

	public static class PromoteStatus {
		/**
		 * 状态信息 loading: 正在登陆, error: 多种状态信息(可重新发起),
		 * promoteCompleted: 提额成功, promoteFailed: 提额失败,
		 * success: 没有任何保单信息，可以提交提额
		 */
		public String msg;
		/**
		 * loading, error, promoteCompleted,
		 * promoteFailed, success
		 */
		public String code;

		public PromoteStatus(String msg, String code) {
			this.msg = msg;
			this.code = code;
		}
	}

}
